﻿using Md.Api.Model;
using Md.Api.Model.Manage.MdProduct.Request;
using Md.Api.Service.Manage.MdProduct;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Md.Api.Controllers.Manage;
/// <summary>
/// 产品
/// </summary>
[ApiController]
[Produces("application/json")]
[Route("md-api/manage/md/product")]
public class MdProductController : ControllerBase
{
    /// <summary>
    /// 通过编号删除产品服务
    /// </summary>
    public DeleteMdProductByIdService deleteMdProductByIdService { get; set; }
    /// <summary>
    /// 通过编号删除产品
    /// </summary>
    /// <param name="productIds">产品编号多个逗号分割（1,2,3...）</param>
    /// <param name="signModel">加密实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpDelete("{productIds}")]
    public async Task<ResponseMessageModel> DeleteMdProductById(string productIds, [FromQuery] RequestSignModel signModel)
    {
        var model = new RequestDeleteMdProductByIdModel();

        model.Ids = productIds;
        model.TimesTamp = signModel.TimesTamp;
        model.Mac = signModel.Mac;
        model.Ip = signModel.Ip;
        model.Sign = signModel.Sign;
        model.Version = signModel.Version;
        model.Token = signModel.Token;

        return await Task.Run(() => deleteMdProductByIdService.Execute(model));
    }

    /// <summary>
    /// 添加产品服务
    /// </summary>
    public InsertMdProductService insertMdProductService { get; set; }
    /// <summary>
    /// 添加产品
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpPost, AllowAnonymous]
    public async Task<ResponseMessageModel> InsertMdProduct([FromBody] RequestInsertMdProductModel model)
    {
        return await Task.Run(() => insertMdProductService.Execute(model));
    }

    /// <summary>
    /// 通过编号更新产品服务
    /// </summary>
    public UpdateMdProductByIdService updateMdProductByIdService { get; set; }
    /// <summary>
    /// 通过编号更新产品
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpPut]
    public async Task<ResponseMessageModel> UpdateMdProductById([FromBody] RequestUpdateMdProductModel model)
    {
        return await Task.Run(() => updateMdProductByIdService.Execute(model));
    }

    /// <summary>
    /// 通过编号获取产品服务
    /// </summary>
    public GetMdProductByIdService getMdProductByIdService { get; set; }
    /// <summary>
    /// 通过编号获取产品
    /// </summary>
    /// <param name="productId">产品编号</param>
    /// <param name="signModel">加密实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpGet("{productId}")]
    public async Task<ResponseMessageModel> GetMdProductById(long productId, [FromQuery] RequestSignModel signModel)
    {
        var model = new RequestGetMdProductByIdModel();

        model.ProductId = productId;
        model.TimesTamp = signModel.TimesTamp;
        model.Mac = signModel.Mac;
        model.Ip = signModel.Ip;
        model.Sign = signModel.Sign;
        model.Version = signModel.Version;
        model.Token = signModel.Token;

        return await Task.Run(() => getMdProductByIdService.Execute(model));
    }

    /// <summary>
    /// 获取体验产品列表服务
    /// </summary>
    public GetMdProductExperienceListService getMdProductExperienceListService { get; set; }
    /// <summary>
    /// 获取体验产品列表
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [Route("experienceList"), HttpPost]
    public async Task<ResponseMessageModel> GetMdProductExperienceList([FromBody] RequestGetMdProductExperienceListModel model)
    {
        return await Task.Run(() => getMdProductExperienceListService.Execute(model));
    }

    /// <summary>
    /// 获取产品列表服务
    /// </summary>
    public GetMdProductListService getMdProductListService { get; set; }
    /// <summary>
    /// 获取产品列表
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [Route("list"), HttpPost]
    public async Task<ResponseMessageModel> GetMdProductList([FromBody] RequestGetMdProductListModel model)
    {
        return await Task.Run(() => getMdProductListService.Execute(model));
    }

    /// <summary>
    /// 分页获取产品列表服务
    /// </summary>
    public GetMdProductPageListService getMdProductPageListService { get; set; }
    /// <summary>
    /// 分页获取产品列表
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [Route("listPage"), HttpPost]
    public async Task<ResponseMessageModel> GetMdProductPageList([FromBody] RequestGetMdProductPageListModel model)
    {
        return await Task.Run(() => getMdProductPageListService.Execute(model));
    }
}

